package com.space.school.controller;

import com.space.school.domain.ProductCategory;
import com.space.school.service.impl.ProductListServiceImpl;
import com.space.school.utils.PageBean;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Map;

@WebServlet(name = "productInfoByPageServlet",value = "/productInfoByPageServlet")
public class ProductListServlet extends HttpServlet {
    private ProductListServiceImpl productListService = new ProductListServiceImpl();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        String currentPage=req.getParameter("currentPage");
        if(currentPage==null || currentPage.isEmpty()) {
            currentPage="1";
        }
        int pageSize=3;
        Map<String,String[]> map=req.getParameterMap();
        PageBean<ProductCategory> pb=productListService.search(map,Integer.parseInt(currentPage), pageSize);
        req.setAttribute("pb",pb);
        req.getRequestDispatcher("productList.jsp").forward(req,resp);
    }
}
